var app = angular.module('webApp', ['ui.router', 'oc.lazyLoad', 'ngCookies','iService','iDirective','Filter']);
// 页面路由
app.config(['$controllerProvider','$stateProvider','$urlRouterProvider', '$locationProvider','$ocLazyLoadProvider',function($controllerProvider,$stateProvider,$urlRouterProvider,$locationProvider,$ocLazyLoadProvider) {
    //动态拆分控制器，指令，过滤器，工厂，服务
    app.register = {
        controller: $controllerProvider.register,
        /*directive: $compileProvider.directive,
        filter: $filterProvider.register,
        factory: $provide.factory,
        service: $provide.service,
        constant: $provide.constant*/
    };
    //路由状态重写
    var loadResolve = function (files,options) {
        var loadPlugin = {
            deps: ['$ocLazyLoad', function($ocLazyLoad) {
                return $ocLazyLoad.load({
                    files: files
                });
            }]
        }
        if(options){
            angular.forEach(options,function (value,key) {
                loadPlugin[key] = value;
            })
        }
        return loadPlugin;
    }
    //动态路由
    $stateProvider
    .state('home', {    //首页
        url:'/',
        templateUrl: __uri('/views/home.html'),
        controller:'homeCtrl',
        resolve : loadResolve([__uri('/src/css/home.less')])
    })
    $urlRouterProvider.otherwise('/');
    // $locationProvider.html5Mode(true);
    $locationProvider.hashPrefix('');


}]);

// 在所有route跳转前进行登录检查，目标页面需要登录且用户未登录，则跳转到登录页面
app.run(['$rootScope', '$cookies', '$location', function($rootScope,$cookies,$location) {
    $rootScope.$on('$stateChangeStart', function(event, toState, toParams, fromState, fromParams) {
        window.scrollTo(0,0);
    })
}]);

app.controller('appCtrl',['$scope','$rootScope','$location','$timeout','$cookies', function ($scope,$rootScope,$location,$timeout,$cookies) {

}]);
